<%-- 

--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<%@ page import="org.apache.commons.fileupload.*,
                 org.apache.commons.fileupload.servlet.ServletFileUpload,
                 java.util.*, java.io.InputStream, java.lang.Exception" %>

<html>
  <head>
    <title>File Upload Example</title>
  </head>

  <body>
    <h1>Data Received at the Server</h1>
    <hr/>
    <p>

<%
if (ServletFileUpload.isMultipartContent(request))
{
  ServletFileUpload servletFileUpload = new ServletFileUpload();
  FileItemIterator fileItemIterator = servletFileUpload.getItemIterator(request);

  while (fileItemIterator.hasNext())
  {
    FileItemStream fileItemStream = fileItemIterator.next();
    if (fileItemStream.isFormField())
    {
        continue;
    }

    long fileSize = 0;

    InputStream in = fileItemStream.openStream();

    while(in.read() >= 0)
    {
        fileSize ++;
    }

    in.close();
%>

<b>Uploaded File Info:</b><br/>
Content type: <%= fileItemStream.getContentType() %><br/>
Field name: <%= fileItemStream.getFieldName() %><br/>
File name: <%= fileItemStream.getName() %><br/>
File size: <%= fileSize %> bytes<br/><br/>


<%
  }
}
%>


    </p>
  </body>
</html>

